home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PBLIB1 / PROGS / TLISTER.PAS < prev    next >
Pascal/Delphi Source File  |  1994-05-03  |  7KB  |  246 lines

  1. (*PAGE*)
  2. PROGRAM TLISTER;
  3.  
  4. Uses DOS, CRT, PbCRT, PbMISC, PbDATA, PbOBJS, PbHIGH, PbPARMS;
  5.  
  6. {
  7. Description :  Pascal Source file printer
  8.  
  9. Author      : Howard Richoux
  10. Date        : 11/89
  11. Last revised: lots over a long time
  12.               2/18/94   3.02 NEW LIBRARIES
  13. Application : IBM PC and compatibles, done in Turbo Pascal 7.0
  14. Status      : Placed in the Public Domain by HNR Software 1/29/94
  15. Published in: none
  16. }
  17.  
  18.  
  19.  
  20. var S            : string;
  21.     outfile      : string[40];
  22.     fname        : string[40];
  23.  
  24. var L : OUT_object_1;
  25.  
  26.     compressed        : boolean;
  27.     InterfaceOnlyFlag : boolean;
  28.  
  29.  
  30. {*****************************************************************}
  31.  
  32.  
  33. Function Command(line : string) : boolean;
  34. var i : integer;
  35.     begin
  36.     Command := false;
  37.     if (copy(line,1,6) = '(*PAGE') or (copy(line,1,5) = '{PAGE') then
  38.          begin
  39.          Command := true;
  40.          i := length(line);
  41.          if i > 9 then L.pagelabel1 := copy(line,7,i-9);
  42.          L.donewithpage;
  43.          end;
  44.     end;
  45.  
  46.  
  47.  
  48. Procedure ListFile(fname : string);
  49. var line,cmd : string;
  50.     done : boolean;
  51.     tx   : TFILE_object;
  52.     begin
  53.     if not FileExists(fname) then
  54.         begin
  55.         writeln('');
  56.         writeln('Listfile - file not found [',fname,']');
  57.         exit;
  58.         end;
  59.     writeln('Listing file ',fname);
  60.  
  61.     L.ResetCounts;
  62.     pCurrFName := UpCaseStr(fname);
  63.     L.pagelabel1 := Packtimestr(FileDate(pCurrFname,''));
  64.  
  65.     tx.init(pCurrFName,false);
  66.     done := false;
  67.     while tx.fetchnext(line) and not done do
  68.         begin
  69.         if not Command(line) then
  70.              begin
  71.              L.out(line);
  72.              if InterfaceOnlyFlag then
  73.                   begin
  74.                   cmd := UpCaseStr(leftstr(line,14));
  75.                   trim(cmd);
  76.                   if cmd = 'IMPLEMENTATION' then done := true;
  77.                   end;
  78.              end;
  79.         if keypressed then done := true;
  80.         end;
  81.     tx.done;
  82.     L.donewithpage;
  83.     end;
  84.  
  85.  
  86. Function IsThisUnitFile(fname : string) : boolean;
  87.          {check the first 100 lines for the word 'INTERFACE'}
  88. var line : string;
  89.     count, printed : integer;
  90.     done : boolean;
  91.     found : boolean;
  92.     tx   : TFILE_object;
  93.     begin
  94.     found := false;
  95.     done := false;
  96.     count := 200; printed := 0;
  97.     pCurrFName := UpCaseStr(fname);
  98.     tx.init(pCurrFName,false);
  99.     while tx.fetchnext(line) and not done do
  100.         begin
  101.         trim(line);
  102.         if leftstr(UpCaseStr(line),9) = 'INTERFACE' then found := true;
  103.         if keypressed then done := true;
  104.         inc(printed);
  105.         if printed > count then done := true;
  106.         if found then done := true;
  107.         end;
  108.     tx.done;
  109.     if found and pDEBUG then
  110.          writeln('IsThisUnitFile? ',leftstr(fname,24),'  YES')
  111.     else if pDEBUG then
  112.          writeln('IsThisUnitFile? ',leftstr(fname,24),'  NO');
  113.     IsThisUnitFile := found;
  114.     end;
  115.  
  116.  
  117. Function LocateFile(var fn : string) : boolean;
  118. var i :integer;
  119.     found : boolean;
  120.     begin
  121.     found := true;
  122.     if      FileExists(fn + '.pas') then fn := fn + '.pas'
  123.     else if FileExists(fn + '.txt') then fn := fn + '.txt'
  124.     else if FileExists(fn + '.doc') then fn := fn + '.doc'
  125.     else found := false;
  126.     if InterfaceOnlyFlag and (not IsThisUnitFile(fn)) then
  127.         found := false;
  128.     LocateFile := found;
  129.     end;
  130.  
  131.  
  132. Function ExcludeFile(var fn : string) : boolean;
  133. var exclude : boolean;
  134.     exten   : string[4];
  135.     begin
  136.     exten := UpCaseStr(rightstr(fn,4));
  137.     if      exten = '.OBJ' then exclude := true
  138.     else if exten = '.EXE' then exclude := true
  139.     else if exten = '.COM' then exclude := true
  140.     else if exten = '.MAP' then exclude := true
  141.     else if exten = '.LST' then exclude := true
  142.     else if exten = '.ARC' then exclude := true
  143.     else if exten = '.ZIP' then exclude := true
  144.     else if exten = '.BAK' then exclude := true
  145.     else if exten = '.TPU' then exclude := true
  146.     else exclude := false;
  147.     if InterfaceOnlyFlag and (not IsThisUnitFile(fn)) then
  148.         exclude := true;
  149.     ExcludeFile := exclude;
  150.     end;
  151.  
  152.  
  153.  
  154.  
  155. Procedure ListFiles(fn : string);
  156. var SR :searchrec;
  157.     i  : integer;
  158.     fname : string[80];
  159.     fnarray : STRA_object;
  160.     begin
  161.     fname := fn;
  162.     i := Pos('.',fname);
  163.     if i = 0 then
  164.          begin
  165.          if LocateFile(fname) then ListFile(fname);
  166.          end
  167.     else begin
  168.          i := Pos('*',fname);
  169.          if i = 0 then Listfile(fname)
  170.          else begin
  171.               fnarray.init(100);
  172.               GetfilesSTRA(fname,fnarray,fNoSort);
  173.               if fnarray.count > 0 then
  174.                    begin
  175.                    fnarray.sort;
  176.                    for i := 1 to fnarray.count do
  177.                         begin
  178.                         s := fnarray.fetchN(i);
  179.                         if not ExcludeFile(s) then ListFile(s);
  180.                         end;
  181.                    end;
  182.               fnarray.done;
  183.               end;
  184.          end;
  185.     end;
  186.  
  187.  
  188. Procedure Init;
  189. var yy,mm,dd : word;
  190.     fname,temp,hdr : string;
  191.     i : integer;
  192.     begin
  193.  
  194.     addparm(1,'OUT','');
  195.     addparm(1,'APPEND','NO');
  196.     addparm(1,'INTERFACE','NO');
  197.     addparm(1,'COMPRESSED','NO');
  198.  
  199.     StandardpVarsInit;     { PARMunit standard variables }
  200.  
  201.     InterfaceOnlyFlag := CheckOK('INTERFACE');
  202.     compressed        := CheckOK('COMPRESSED');
  203.  
  204.  
  205.     Outfile         := UpCaseSTr(GetParmStr('OUT'));
  206.     if outfile <> '' then
  207.          begin
  208.          if CheckOK('APPEND') then
  209.               writeln('appending to: ',outfile)
  210.          else writeln('listing to: ',outfile);
  211.  
  212.          L.LISTinit(outfile,OUT_typAPPEND);
  213.          if compressed then L.SetCompressed;
  214.          hdr := '@LABEL1     |@FILE|Page @PAGE';
  215.          if InterfaceOnlyFlag then
  216.               hdr := '@LABEL1 |@FILE|(INTERFACE ONLY)  Page @PAGE';
  217.          L.SetHeaders(hdr,' ','',
  218.                       '||@PROGID',' ');
  219.          L.LISTOpen;
  220.          end;
  221.     end;
  222.  
  223.  
  224. (*  Main program *)
  225.     BEGIN
  226.     pProgID := 'TLISTER 3.02';
  227.     Init;
  228.  
  229.     fname := 'x';
  230.     if ParamCount > 0 then
  231.          begin
  232.          fname := UpCaseStr(paramstr(1));
  233.          if      fname = 'HELP'   then ShowDocFile
  234.          else if fname = 'STATUS' then ListParms(0)
  235.          else begin
  236.               ListFiles(fname);
  237.               L.done;
  238.               writeln('');
  239.               writeln('LISTER done');
  240.               end;
  241.          end
  242.     else ShowDocFile;
  243.     end.
  244.  
  245.  
  246.